#ifndef SERVER_H
#define SERVER_H
#ifdef _WIN32
#include <winsock2.h>
#pragma comment(lib,"Ws2_32.lib")
#endif
#ifdef linux
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#endif
#include <exception>
#include <iostream>
#include <string>
#include <algorithm>
#include "data.h"
#include "map.h"
#include <time.h>
using namespace std;
class server
{
protected :
    int sv_lis;//server listen
    int *cl_con;//client connect
    unsigned int port;//port server
    unsigned int num_cl;//number client
    //string sv_addr;//dia chi server
    string *user;//user nickname
    map *table;//ban do
    int *point;//diem cua user
	unsigned int num_map;//so o cua ban do
    struct sockaddr_in serv;
    struct sockaddr_in client;
    int step;//bang so o 'X' cua tau
    data sen;
    data rec;
    //khoi tao cac thong so
    void init();

    void getparametter();

    int createsocket();

    int serverlisten();

    int serveraccept();

    int serverbind();
    int serversend(int id);

    int serversendall();
	void serversrf();
    int serverrecv(int id);
    int login(int id);
    int checkuser(int id);
	int checkchar(char c);
    void makevaluegame();
    int processresult(int id);
    int checkmax();
    void playgame();

    void control();
    void serverintro();
    void start();
    void serverclose();

public:
    server();
    ~server();
    void run();


};
#endif // SERVER_H
